package com.nd.android.u.ui.beanStarApp;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.AvoidXfermode;
import android.os.Bundle;
import android.text.SpannableString;
import android.widget.ImageView;

import com.common.allCommon.StarAppHeadImageLoader;
import com.common.android.utils.smiley.Smiley;
import com.nd.android.u.allCommonUtils.ToastUtils;
import com.nd.android.u.chatInterfaceImpl.ChatInterfaceImpl;
import com.nd.android.u.controller.ChatConst;
import com.nd.android.u.controller.ChatConst.KEY;
import com.nd.android.u.controller.bean.contact.BasePersonContactItem;
import com.nd.android.u.controller.bean.contact.ForwardingParam;
import com.nd.android.u.ui.ChatEntry;
import com.nd.android.u.ui.R;
import com.nd.android.u.ui.chatUiUtils.ChatCommonUtils;
import com.nd.android.u.ui.chatUiUtils.ChatViewUtil;
import com.product.android.business.ApplicationVariable;

/**
 * 个人消息联系人
 * <br>Created 2014-10-30 下午2:36:27
 * @version  
 * @author   cb		
 * @see 	 
 */
public class PersonContactItem extends BasePersonContactItem{
	@Override
	public SpannableString getContentText() {
		if (spannableText==null){
			spannableText=ChatCommonUtils.getSmileySpannableString(mLastMsgContent,Smiley.TYPE_CHAT, mLastMsgId);	
		}
	    return spannableText;
	}

	@Override
	public void onClickHeadPortrait(Context ctx) {
		long id = convertId();
		if (id < 0) {
			return;
		}
		if (isIgnoreItem(id)) {
			return;
		}

		ChatEntry.INSTANCE.chatCallOtherModel_UI.gotoPersonalDynamicActivity(
				ctx, id);
	}

	/**
	 * 是否不能转发的联系人
	 * <br>Created 2014-10-30 下午2:55:40
	 * @param id
	 * @return
	 * @author  cb
	*/
	private boolean isIgnoreItem(long id) {
		// 过滤
		// 10003057 E-learning系统提醒
		// 666666666 ERP系统提醒
		// 999999999 网龙公司管理系统
		if ((id == 10003057) || (id == 666666666) || (id == 999999999)) {
			return true;
		} else {
			return false;
		}
	}
	
	@Override
	public void onForwarding(final Activity activity,
			ForwardingParam forwardingParam) {
		long id = convertId();
		if (id < 0) {
			return;
		}
		
		if(forwardingParam == null){
			return;
		}

		if (isIgnoreItem(id)) {
			ToastUtils.display(activity, R.string.chat_transmit_owner);
			return;
		}
		if (id == forwardingParam.mId) {
			ToastUtils.display(activity, R.string.chat_transmit_owner);
			// 转发给消息的发送者
			return;
		}
		if (id == ChatInterfaceImpl.INSTANCE.chatCallOtherModel.getOapUid()) {
			// 转发给自己
			ToastUtils.display(activity, R.string.chat_transmit_self);
			return;
		}
		Intent intent = new Intent(activity, getDisplayClass());
		Bundle bundle = new Bundle();
		bundle.putLong(ChatConst.KEY.FID, id);
		bundle.putString(KEY.NAME, name);
		bundle.putString(ChatConst.KEY.REPOST_DATA, forwardingParam.mGenerateId);
		intent.putExtras(bundle);
		ChatViewUtil.showDlg(activity, intent,getMsgTitle(activity));
	}
	
	@Override
	public void displayHeadPortrait(ImageView iv) {
		// StarAppHeadImageLoader.displayCircleImage(convertId(),
		// StarAppHeadImageLoader.IMAGE_TYPE_HEAD_100, iv, null);
		// FID s 个人消息联系人uid
		StarAppHeadImageLoader.displayCircleImageByUid(
				ApplicationVariable.INSTANCE.applicationContext, convertId(),
				StarAppHeadImageLoader.IMAGE_TYPE_HEAD_100, iv, null, -1, -1);
	}

}
